<?php
class ArticleCommAction extends BaseAction{
	/**
	 * 学校交流列表
	 */
	public function article_comm(){
		$ac_id = $_GET['c_id'];
		$where = '';
		if ($ac_id){
			$where .= "ac_id=$ac_id";
		}else{
			$where .="ac_id in (4,5,6)";
		}
		$where .=  $this->my_where();
		import('ORG.Util.Page');// 导入分页类
		$count = M('Article')->where($where)->count();
		$Page = new Page($count,10);//每页显示10条
		$show = $Page->show();
		$ac_list = M('ArticleClass')->where('p_id=3')->select();
		//获取文章分类，返回数组
		$ac_list_ = array();
		foreach ($ac_list as $k=>$v){
			$ac_list_[$v['id']] = $v;
		}
		$list = M('Article')->where($where)->order('sort')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign("list",$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->assign("ac_list",$ac_list_);
		$this->display();
	}
	public function article_comm_add(){
		if($_POST){
			$_POST['time'] = time();
			$_POST['visits'] = 0;
			$_POST['upvote'] = 0;
			$_POST['content'] = stripslashes($_POST['content']);
			M('Article')->add($_POST);
			$this->success('添加成功',U('ArticleComm/article_comm'));
			exit;
		}
		$ac_list = M('ArticleClass')->where('p_id=3')->select();
		$this->assign("ac_list",$ac_list);
		$this->display();
	}
	/**
	 * 学校交流修改方法
	 */
	public function article_comm_update(){
		if ($_POST){
			$_POST['content'] = stripslashes($_POST['content']);
			M('Article')->save($_POST);
			$this->success('更新成功',U('ArticleComm/article_comm',array('p'=>$_POST['p'],'c_id'=>$_POST['c_id'],'search_word'=>$_POST['search_word'])));
			exit;
		}
		$search_word = $_GET['search_word'];
		$p = $_GET['p'];
		$c_id = $_GET['c_id'];
		$obj = M('Article')->where("id=".$_GET['id'])->find();
		$ac_list = M('ArticleClass')->where('p_id=3')->select();
		$this->assign("ac_list",$ac_list);
		$this->assign("obj",$obj);
		$this->assign('p',$p);
		$this->assign('c_id',$c_id);
		$this->assign('search_word',$search_word);
		$this->display();
	}
	public function article_comm_delete(){
		M('Article')->where("id=".$_GET['id'])->delete();
		$this->success('删除成功');
	}
	public function comment_list(){
		$w['a_id'] = $_GET['id'];
		import('ORG.Util.Page');// 导入分页类
		$count = M('Comment')->where($w)->count();//总条数
		$Page = new Page($count,10);//每页显示10条
		$show = $Page->show();
		$list = M('Comment')->where($w)->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('list',$list);
		$this->assign('page',$show);// 赋值分页输出
		$this->display();//输出模板
	}
	/**
	 * 删除操作
	 */
	public function comment_delete(){
		M('Comment')->where('id='.$_GET['id'])->delete();
		$this->success('删除成功','article_comm');
	}
	//搜索配置
	public function my_where(){
		$where = '';
		$search_word = $_GET['search_word'];
		if($search_word) {
			$where .= " and (title like '%$search_word%') ";
		}
		return $where;
	}
}

?>